package LuoGu.入门.校门外的树;

/**
    三种解法：模拟计数
    线段树
    分块
 */

import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int l = s.nextInt();
        int n = s.nextInt();
        int ans [][] = new int [n][2];
        for(int i=0;i<n;i++){
            ans[i][0] = s.nextInt();
            ans[i][1] = s.nextInt();
        }
        Arrays.sort(ans, (o1, o2) -> {
            if(o1[0]>=o2[0]) return 1;
            else return -1;
        });
        for(int i=0;i<n-1;i++){
            if(ans[i][1]>ans[i+1][0]);
        }
    }
}